<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Login_model extends Model{
    function Login_model(){
        parent::Model();
    }

    function cekLogin(){
        $this->load->library('reg_validation');
        $username = $this->input->post('usernameLogin');
        $password = $this->input->post('passwordLogin');
        if ($this->reg_validation->cek_form_input('username',$username)
                && $this->reg_validation->cek_form_input('password',$password)){
            $password = md5($password);
            //cek ke database
            //cek username dan password
            $this->db->where('username',$username);
            $this->db->where('password',$password);
            $query = $this->db->get('pegawai');
            if ($query->num_rows() == 1){
                //login valid
                //set session
                $this->session->sess_destroy();
                $this->session->sess_create();
                $userdata = array(
                   'logged_in' => true,
                  'username' => $username
                );
                $this->session->set_userdata($userdata);
                
            }
            $data = array(
                'username' => $this->session->userdata('username'),
                'logged_id' => $this->session->userdata('logged_in'),
            );
            return $data;
        }
    }
}
?>
